﻿#include <QModbusTcpClient>
#include <QDebug>
#include "QTcpModbus.h"

QTcpModbus::QTcpModbus(QObject *parent) : QSerialPortModbus(parent)
{

}

void QTcpModbus::SetCommunicationParam(QString communicationParam)
{
    BaseCommunication::SetCommunicationParam(communicationParam);
    modbusDevice = new QModbusTcpClient();
    const QUrl url = QUrl::fromUserInput(_communicationParam);
    if(!url.isValid())
    {
        throw QString("QTcpModbus通讯参数格式有问题!");
    }
    modbusDevice->setConnectionParameter(QModbusDevice::NetworkAddressParameter,url.host());
    modbusDevice->setConnectionParameter(QModbusDevice::NetworkPortParameter,url.port());
}
